package com.baidu.bos.web.action;

import java.sql.Timestamp;
import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.baidu.bos.domain.Noticebill;
import com.baidu.bos.domain.Staff;
import com.baidu.bos.domain.Workbill;
import com.baidu.bos.service.IWorkbillService;
import com.baidu.bos.web.action.base.BaseAction;
@Controller
@Scope("prototype")
public class WorkbillAction extends BaseAction<Workbill>{
	@Resource
	private IWorkbillService workbillService;
	
	public String pageQuery(){
		Noticebill noticebill = model.getNoticebill();
		Staff staff = model.getStaff();
		DetachedCriteria dc = pageBean.getDetachedCriteria();
		Timestamp buildtime = model.getBuildtime();
		if (buildtime != null) {
			dc.add(Restrictions.like("buildtime", "%"+buildtime+"%"));
		}
		if (noticebill != null) {
			dc.createAlias("noticebill", "n");
			String telephone = noticebill.getTelephone();
			dc.add(Restrictions.like("n.telephone", "%"+telephone+"%"));
		}
		if (staff != null) {
			dc.createAlias("staff", "s");
			String staffName = staff.getName();
			dc.add(Restrictions.like("s.name", "%"+staffName+"%"));
		}
		workbillService.pageQuery(pageBean);
		this.writeObject2Json(pageBean);
		return NONE;
	}
}
